package com.uroboros.spring.guides.caching;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

@EnableCaching
@SpringBootApplication
public class SpringGuidesCachingApplication {

	private static final Logger logger = LoggerFactory.getLogger(SpringGuidesCachingApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(SpringGuidesCachingApplication.class, args);
	}

	@Bean
	public CommandLineRunner init(BookRepository bookRepository) {
		return args -> {
			logger.info(".... Fetching books");
			logger.info("isbn-1234 -->" + bookRepository.findByIsbn("isbn-1234"));
			logger.info("isbn-4567 -->" + bookRepository.findByIsbn("isbn-4567"));
			logger.info("isbn-1234 -->" + bookRepository.findByIsbn("isbn-1234"));
			logger.info("isbn-4567 -->" + bookRepository.findByIsbn("isbn-4567"));
			logger.info("isbn-1234 -->" + bookRepository.findByIsbn("isbn-1234"));
			logger.info("isbn-1234 -->" + bookRepository.findByIsbn("isbn-1234"));
		};
	}

}
